#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QFontDatabase>
#include <QLockFile>
#include <QDir>
#include "logindialog.h"

void setGlobalFont() {
    int fontId = QFontDatabase::addApplicationFont("://fonts/ltjh.ttf");
    if (fontId == -1) {
        qDebug() << "字体加载失败";
        return;
    }
    // 获取字体家族名称
    QStringList families = QFontDatabase::applicationFontFamilies(fontId);
    if (!families.isEmpty()) {
        // 设置全局字体
        QFont font(families.first());
        QApplication::setFont(font);
    }
}

int main(int argc, char *argv[])
{
    QLockFile lockFile(QDir::temp().absoluteFilePath("App.lock"));
    if (!lockFile.tryLock(100)) {
        qDebug() << "程序已运行";
        return 0;
    }

    QApplication a(argc, argv);
    setGlobalFont();

    LoginDialog loginDialog;

    qDebug() << "start login.";
    if (loginDialog.exec() == QDialog::Accepted) {
        qDebug() << "start main";
        MainWindow w;
        w.show();
        return a.exec();
    }

    return 0;
}
